package application

import (
	"context"
	"zxstudy.com/domain/entity"
	"zxstudy.com/domain/repository"
)

type userApp struct {
	repo repository.UserRepository
}

type UserApplication interface {
	Register(ctx context.Context, user *entity.User) (*entity.User, error)
	Update(ctx context.Context, user *entity.User) (*entity.User, error)
	Get(ctx context.Context, id int) (*entity.User, error)
	Users(ctx context.Context) ([]*entity.User, error)
}

func NewUserApplication(repo repository.UserRepository) *userApp {
	return &userApp{repo}
}

func (u *userApp) Register(ctx context.Context, user *entity.User) (*entity.User, error) {
	return u.repo.Register(ctx, user)
}

func (u *userApp) Update(ctx context.Context, user *entity.User) (*entity.User, error) {
	return u.repo.Update(ctx, user)
}

func (u *userApp) Get(ctx context.Context, id int) (*entity.User, error) {
	return u.repo.Get(ctx, id)
}

func (u *userApp) Users(ctx context.Context) ([]*entity.User, error) {
	return u.repo.Users(ctx)
}